﻿/**
  ******************************************************************************
  * @file    Libraries/Device/JS32T031/JS32T031_LL_Driver/inc/js32t031_ll_timer.h
  * @author  JUSHENG Application Team
  * @version V1.0.0
  * @date    02-19-2022
  * @brief   This file contains all the TIMER LL firmware functions.
  ******************************************************************************
  * @attention
  *
  * <h2><center>&copy; COPYRIGHT 2022 JUSHENG</center></h2>
  *
  *
  *
  ******************************************************************************
  */ 
  
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __JS32T031_LL_TIMER_H
#define __JS32T031_LL_TIMER_H

#ifdef __cplusplus
 extern "C" {
#endif

/* Includes ------------------------------------------------------------------*/
#include "typedef.h"
#include "js32t031.h"
     
/** @addtogroup JS32T031_StdPeriph_Driver JS32T031 Driver
  * @{
  */
     
/** @addtogroup timer_interface_gr TIMER Driver
  * @ingroup  JS32T031_StdPeriph_Driver
  * @{
  */ 

/** @addtogroup TIMER_LL_Driver TIMER LL Driver
  * @ingroup  timer_interface_gr
  * @brief Mainly the driver part of the TIMER module, which includes \b TIMER \b Register 
  * \b Constants, \b TIMER \b Exported \b Constants, \b TIMER \b Exported \b Struct, \b TIMER
  * \b Data \b transfers \b functions, \b TIMER \b Initialization \b and \b TIMER \b Configuration 
  * \b And \b Interrupt \b Handle \b function.
  * @{
  */
     
/* Exported types ------------------------------------------------------------*/

/* Exported constants --------------------------------------------------------*/
     
/** @defgroup TIMER_LL_Register_Constants TIMER LL Register Constants
  * @ingroup  TIMER_LL_Driver
  * @brief    TIMER LL register constant table definition
  *
  *
@verbatim   
  ===============================================================================
                                Register Constants
  ===============================================================================  
  
    Register Constants mainly encapsulates each bit in each group in the TIMER 
    register. In the process of configuration, the macro definition can be directly 
    called to configure the TIMER register, mainly for convenience. Understand the 
    configuration of the TIMER.
    
@endverbatim
  *
  * @{
  */

/***** TMRx_CON *****/
/*! RW, TIMERx timer counter source edge select
 */
#define LL_TIMER_CON_EDGE_SEL(n)                             (((n)&0x3) << 26)

/*! RW, TIMERx Gate keep mode select
*/
#define LL_TIMER_CON_GATE_KEEP_MODE_SEL                     (1UL << 25)

/*! RW, TIMERx Capture event 2 polarity
 */
#define LL_TIMER_CON_CAP2_POL                               (1UL << 22)

/*! RW, TIMERx Capture event 1 polarity
 */
#define LL_TIMER_CON_CAP1_POL                               (1UL << 21)

/*! RW, TMR_PWM_CON polarity selection  
 */
#define LL_TIMER_CON_PWM_POL                             (1UL << 21)

/*! RW, TIMERx When capture event 2 occurs, the CNT value clears to zero
 */
#define LL_TIMER_CON_CAP2_CNT_RESET                         (1UL << 18)

/*! RW, TIMERx When capture event 1 occurs, the CNT value clears to zero
 */
#define LL_TIMER_CON_CAP1_CNT_RESET                         (1UL << 17)


/*! RW, TIMERx the number of the Capture register  
 * 0 : Capture data store in CAP1  
 * 1 : Capture data store in CAP1 CAP2  
 */
#define LL_TIMER_CON_CAP_REGISTER_CNT                       (1UL << 15)

/*! RW, TIMERx Capture selection
 */
//#define LL_TIMER_CON_CAP_SEL(n)                             (((n)&0x3) << 13)

/*! RW, TIMERx Output synchronization signal selection
 * 00 : CNT == TMR_PRD  
 * 01 : CNT == TMR_CMP  
 * 10 : Output the SYNCI value to SYNCO  
 * 11 : Output the PWM value to SYNCO  
 */
#define LL_TIMER_CON_SYNCO_SEL(n)                           (((n)&0x3) << 11)

/*! RW, TIMERx Synci polarity reversed
 */
#define LL_TIMER_CON_SYNCI_POL                              (1UL << 10)

/*! RW, TIMERx Synci MODE selection
 */
#define LL_TIMER_CON_SLAVE_MODE(n)                          (((n)&0x3) << 8)

/*! RW, TIMERx timer's prescaler setting
 */
#define LL_TIMER_CON_DIVISION_SET(n)                        (((n)&0x7) << 5)

/*! RW, TIMERx timer counter source select
 */
#define LL_TIMER_CON_SRC_SEL(n)                             (((n)&0x7) << 2)

/*! RW, TIMERx mode select
 */
#define LL_TIMER_CON_MODE_SET(n)                             (((n)&0x3) << 0)


/***** TMRx_EN *****/
/*! RW, TIMERx enabled  
 */
#define LL_TIMER_EN                                         (1UL << 0)


/***** TMRx_IE *****/
/*! RW, Slave mode trigger mode or reset mode interrupt enable
 */
#define LL_TIMER_IE_SLAVE_MOED_IE                           (1UL << 7)

/*! RW, When CNT value is equal to CMP value, interrupt enable, Only valid in PWM mode
 */
#define LL_TIMER_IE_CNT_CMP_IE                              (1UL << 6)

/*! RW, When CNT value is equal to PRD value, interrupt enable, Only valid in counter/PWM mode
 */
#define LL_TIMER_IE_CNT_PRD_IE                              (1UL << 5)

/*! RW, When CNT value overflows, interrupt enable
 */
#define LL_TIMER_IE_CNT_OVERFLOW_IE                         (1UL << 4)

/*! RW, When capture event 2 occurs, interrupt enable
 */
#define LL_TIMER_IE_CAPTURE2_IE                             (1UL << 1)

/*! RW, When capture event 1 occurs, interrupt enable
 */
#define LL_TIMER_IE_CAPTURE1_IE                             (1UL << 0)

/*! RW, Capture event 1 to 2 interrupt enable set
 */
#define LL_TIMER_IE_CAPTURE_IE_SET(n)                       (((n)&0x3) << 0)


/***** TMRx_FLG *****/
/*! RO, Slave mode occurs pending (reset or triggered only)
 */
#define LL_TIMER_FLG_SLAVE_MOED_PENDING                     (1UL << 7)

/*! RO, The CNT value is equal to the CMP value pending, which is only valid in PWM mode
 */
#define LL_TIMER_FLG_CNT_CMP_PENDING                        (1UL << 6)

/*! RO, The CNT value is equal to the PRD value pending, which is valid only in counter/PWM mode
 */
#define LL_TIMER_FLG_CNT_PRD_PENDING                        (1UL << 5)

/*! RO, The CNT value overflow pending
 */
#define LL_TIMER_FLG_CNT_OVERFLOW_PENDING                   (1UL << 4)

/*! RO, The capture event 2 occurrence pending
 */
#define LL_TIMER_FLG_CAPTURE2_PENDING                       (1UL << 1)

/*! RO, The capture event 1 occurrence pending
 */
#define LL_TIMER_FLG_CAPTURE1_PENDING                       (1UL << 0)


/***** TMRx_CLR *****/
/*! WO, Slave mode occurs pending clear (reset or triggered only)
 */
#define LL_TIMER_CLR_SLAVE_MOED_PENDING                     (1UL << 7)

/*! WO, CNT value = CMP value pending clear
 */
#define LL_TIMER_CLR_CNT_CMP_PENDING                        (1UL << 6)

/*! WO, CNT value = PRD value pending clear
 */
#define LL_TIMER_CLR_CNT_PRD_PENDING                        (1UL << 5)

/*! WO, CNT value overflow pending clear
 */
#define LL_TIMER_CLR_CNT_OVERFLOW_PENDING                   (1UL << 4)

/*! WO, Capture event 2 occurs with the pending clear
 */
#define LL_TIMER_CLR_CAPTURE2_PENDING                       (1UL << 1)

/*! WO, Capture event 1 occurs with the pending clear
 */
#define LL_TIMER_CLR_CAPTURE1_PENDING                       (1UL << 0)

/*! WO, Clear all pending
 */
#define LL_TIMER_CLR_ALL_PENDING                            (0xFFUL << 0)


/***** TMRx_CAP1 *****/
/*! RW, TIMERx Count register
 */
#define LL_TIMER_PR0_SET(n)                                 (((n)&0xFFFF) << 0)


/***** TMRx_CAP2 *****/
/*! RW, TIMERx Capture register
 */
#define LL_TIMER_CMP0_SET(n)                                (((n)&0xFFFF) << 0)


/***** TMRx_SHADOW *****/
/*! RW, TIMERx Duty shadow register
 */
#define LL_TIMER_CMP_SHADOW_SET(n)                                 (((n)&0xFFFF) << 16)

/*! RW, TIMERx PR shadow register
 */
#define LL_TIMER_PRD_SHADOW_SET(n)                                 (((n)&0xFFFF) << 0)


/***** TMR_ALLCON *****/
/*! WO, UST0_TIMER counts to zero
 */
#define LL_TIMER_ALLCON_UST0_TIMER_CNT_CLR                  (1UL << 10)
/*! WO, Timer1 counts to zero
 */
#define LL_TIMER_ALLCON_TIMER1_CNT_CLR                      (1UL << 9)

/*! WO, Timer0 counts to zero
 */
#define LL_TIMER_ALLCON_TIMER0_CNT_CLR                      (1UL << 8)

/*! WO, UST0_TIMER start count
 */
#define LL_TIMER_ALLCON_UST0_TIMER_START                    (1UL << 2)
/*! WO, Timer1 start count
 */
#define LL_TIMER_ALLCON_TIMER1_START                        (1UL << 1)

/*! WO, Timer0 start count
 */
#define LL_TIMER_ALLCON_TIMER0_START                        (1UL << 0)

/**
  * @}
  */

/** @defgroup TIMER_LL_Exported_Constants TIMER LL Exported Constants
  * @ingroup  TIMER_LL_Driver
  * @brief    TIMER LL external constant definition
  *
@verbatim   
  ===============================================================================
                                Exported Constants
  ===============================================================================  
  
    Exported Constants mainly restricts the partial configuration of the abstraction 
    layer by using the form of enumeration to facilitate the use and understanding of 
    the module configuration. For the specific enumeration meaning, please refer to 
    the annotation of each module.

@endverbatim
  *
  * @{
  */
  
/***** DRIVER API *****/


/***** LL API *****/

/**
  * @brief Enumeration constant for low layer TIMER Prescaler for timer
  */
typedef enum {
    /*! Timer clock source 1 prescaler
     */
    LL_TIMER_PSC_NONE           = 0,
    /*! Timer clock source 2 prescaler
     */
    LL_TIMER_PSC_2,
    /*! Timer clock source 4 prescaler
     */
    LL_TIMER_PSC_4,
    /*! Timer clock source 8 prescaler
     */
    LL_TIMER_PSC_8,
    /*! Timer clock source 16 prescaler
     */
    LL_TIMER_PSC_16,
    /*! Timer clock source 32 prescaler
     */
    LL_TIMER_PSC_32,
    /*! Timer clock source 64 prescaler
     */
    LL_TIMER_PSC_64,
    /*! Timer clock source 128 prescaler
     */
    LL_TIMER_PSC_128, 
} TYPE_ENUM_LL_TIMER_PSC;

/**
  * @brief Enumeration constant for low layer TIMER clock source
  */
typedef enum {
    
    //TODO
    /*! Timer clock source selection: Internal low speed RC divided by 2 clock rising edge 
     */
    LL_TIMER_SRC_SYS_RISING = 0,
    LL_TIMER_SRC_INTERNAL_LOW_SPEED_RC_DIV_2 = 1,
    LL_TIMER_SRC_EXTERNAL_CRYSTAL = 4,
} TYPE_ENUM_LL_TIMER_SRC_SEL;
/**
  * @brief Enumeration constant for low layer TIMER clock source External select
  */
typedef enum {
    /*! Timer clock source selection: pin rising
     */
    LL_TIMER_SRC_INC_PIN_RISING = 0,
    /*! Timer clock source selection: pin falling
     */
    LL_TIMER_SRC_INC_PIN_FALLING,
    /*! Timer clock source selection: pin rising and pin falling 
     */
    LL_TIMER_SRC_INC_PIN_RISING_FALLING,
} TYPE_ENUM_LL_TIMER_EDGE_SEL;

/**
  * @brief Enumeration constant for low layer TIMER Capture selection
  */
typedef enum {
    /*! Timer Capture data store in CAP1
     */
    LL_TIMER_CAP_MODE_CAP1       = 0,
    /*! Timer Capture data store in CAP1 CAP2
     */
    LL_TIMER_CAP_MODE_CAP1_2     = 1,
}TYPE_ENUM_LL_TIMER_CAP_MODE;

/**
  * @brief Enumeration constant for low layer TIMER Capture polarity selection
  */
typedef enum {
    /*! Timer Capture of rising
     */
    LL_TIMER_CAP_POL_RISING       = 0,
    /*! Timer Capture of falling
     */
    LL_TIMER_CAP_POL_FALLING     = 1,
}TYPE_ENUM_LL_TIMER_CAP_POL;


/**
  * @brief Enumeration constant for low layer TIMER the pattern of the timer
  */
typedef enum {
    /*! Timer mode selection: counter mode
     */
    LL_TIMER_MODE_SEL_COUNTER   = 0,
    /*! Timer mode selection: PWM mode
     */
    LL_TIMER_MODE_SEL_PWM       = 1,
    /*! Timer mode selection: capture mode
     */
    LL_TIMER_MODE_SEL_CAPTURE   = 2,
}TYPE_ENUM_LL_TIMER_MODE_SEL;

/**
  * @brief Enumeration constant for low layer TIMER Synchronization signal selection
  */
typedef enum {
    /*! Timer Synchronization selection : CNT value = PRD value
     */
    LL_TIMER_SYNCO_SEL_PRD      = 0,
    /*! Timer Synchronization selection : CNT value = CMP value
     */
    LL_TIMER_SYNCO_SEL_CMP      = 1,
    /*! Timer Synchronization selection : Output the SYNCI value to SYNCO
     */
    LL_TIMER_SYNCO_SEL_SYNCI    = 2,
    /*! Timer Synchronization selection : Output the PWM value to SYNCO
     */
    LL_TIMER_SYNCO_SEL_PWM      = 3,
}TYPE_ENUM_LL_TIMER_SYNCO_SEL;

/**
  * @brief Enumeration constant for low layer slave mode
  */
typedef enum {
    /*! Timer slave mode : disable
     */
    LL_TIMER_SLAVE_MODE_DISABLE = 0,
    /*! Timer slave mode : kicl start
     */
    LL_TIMER_SLAVE_MODE_KICL_START,
    /*! Timer slave mode : reset
     */
    LL_TIMER_SLAVE_MODE_RESET,
    /*! Timer slave mode : gating
     */
    LL_TIMER_SLAVE_MODE_GATING,
}TYPE_ENUM_LL_TIMER_SLAVE_MODE;

/**
  * @brief Enumeration constant for low layer TIMER the pattern of the timer
  */
typedef enum {
    /*! Timer pwm active hight
     */
    LL_TIMER_PWM_ACTIVE_LEVEL_H = 0,
    /*! Timer pwm active low
     */
    LL_TIMER_PWM_ACTIVE_LEVEL_L,
}TYPE_ENUM_LL_TIMER_PWM_ACTIVE_LEVEL_SEL;

/***** LL API AND DRIVER API *****/

/**
  * @}
  */

/** @defgroup TIMER_LL_Exported_Struct TIMER LL Exported Struct
  * @ingroup  TIMER_LL_Driver
  * @brief    TIMER LL external configuration structure definition
  *
@verbatim   
  ===============================================================================
                                Exported Struct
  ===============================================================================  

    Exported Struct mainly extracts the TIMER registers from the API, and abstracts 
    the structure. As long as it implements the low coupling between the registers 
    and the registers, the user only needs to configure the structure of the abstraction 
    layer and call hal_timer_init. Function, you can configure the TIMER module without 
    involving the configuration of the collective register.

@endverbatim
  *
  * @{
  */


/**
  * @brief Low layer TIMER Configure the timer structure
  */
typedef struct __ll_timer_init {
    /*! timer clock source selection
     */
    TYPE_ENUM_LL_TIMER_SRC_SEL          timer_src_sel;
    /*! prescaler value
     */
    TYPE_ENUM_LL_TIMER_PSC              prescaler;
} TYPE_LL_TIMER_INIT;

/**
  * @brief Low layer TIMER count mode Configure the timer structure
  */
typedef struct __ll_timer_cnt_cfg { 
    /*! count cycle value
     */
    u32                                 count_period;
    /*! the initial value of count
     */
    u32                                 count_initial;
    /*! count interrupt enable*/
    FunctionalState                     count_ie;
} TYPE_LL_TIMER_CNT_CFG;



typedef struct __ll_timer_capture_cfg { 
    /*! Capture event 1 polarity selection, 0 : RISING, 1 :FALLING
     */
    TYPE_ENUM_LL_TIMER_CAP_POL         cap1_pol_sel;
    /*! When capture event 1 occurs, the CNT value clears to zero enable
     */
    FunctionalState                     cap1_reset;
    /*! Capture event 1 interrupt enable
     */
    FunctionalState                     cap1_ie;
    
    /*! Capture event 2 polarity selection, 0 : RISING, 1 :FALLING
     */
    TYPE_ENUM_LL_TIMER_CAP_POL         cap2_pol_sel;
    /*! When capture event 2 occurs, the CNT value clears to zero enable
     */
    FunctionalState                     cap2_reset;
    /*! Capture event 2 interrupt enable
     */
    FunctionalState                     cap2_ie;

    /*! Capture event count overflow
     */
    FunctionalState                     cap_overflow;
    
    /*! The number of the Capture register
     */
    TYPE_ENUM_LL_TIMER_CAP_MODE          cap_mode;
} TYPE_LL_TIMER_CAP_CFG;

/**
  * @brief Low layer TIMER capture mode Configure the timer structure
  */
typedef struct __ll_timer_pwm_cfg { 
    /*! pwm cycle count value
     */
    u32                                 pwm_period;
    /*! pwm high voltage count value
     */
    u32                                 pwm_duty;
} TYPE_LL_TIMER_PWM_CFG;

/**
  * @}
  */

/** @defgroup TIMER_LL_Interrupt TIMER LL Interrupt Handle function
  * @brief   TIMER LL Interrupt Handle function
  *
@verbatim   
  ===============================================================================
                        Interrupt Handle function
  ===============================================================================  

    This subsection provides a set of functions allowing to manage the TIMER  
    Interrupt Handle function.

    how to use?

    The TIMER interrupt handler uses a callback method that reserves the interface 
    to the user in the form of a callback function. The client needs to initialize 
    the callback function when initializing the TIMER in order for the interrupt to 
    be processed normally. 
   
@endverbatim
  *
  * @{
  */



/**
  * @}
  */
  
/** @defgroup TIMER_LL_Inti_Cfg TIMER LL Initialization And Configuration
  * @brief    TIMER LL Initialization And Configuration
  *
@verbatim   
  ===============================================================================
                        Initialization And Configuration
  ===============================================================================  

    This subsection provides a set of functions allowing to manage the TIMER data 
    Initialization and Configuration.
    
    how to use?

@endverbatim
  *
  * @{
  */
  
/**
  * @brief  Low layer timer init function
  * @param  p_timer: Set to division and source colock of TIMERx
  * @param  p_init : Configure the p_timer initialization structure
  * @retval None
  */
void ll_timer_init(TIMER_TypeDef *p_timer, TYPE_LL_TIMER_INIT *p_init);
/**
  * @brief  Low layer timer disable function
  * @param  p_timer  : Structure pointer set to TIMERx
  * @retval None
  */
void ll_timer_stop(TIMER_TypeDef *p_timer);

/**
  * @brief  Low layer timer start function
  * @param  p_timer  : Structure pointer set to TIMERx
  * @retval None
  */
void ll_timer_start(TIMER_TypeDef *p_timer, TYPE_ENUM_LL_TIMER_MODE_SEL mode_sel);

/**
  * @brief  Low layer timer cnt set
  * @param  p_timer  : Structure pointer set to TIMERx
  * @param  cnt_set  : timer cnt value(timer0~timer2 16bits cnt value, timer4 32bits cnt value)
  * @retval None
  */
void ll_timer_cnt_set(TIMER_TypeDef *p_timer, u32 cnt_set);

/**
  * @brief  Low layer timer cnt get
  * @param  p_timer  : Structure pointer set to TIMERx
  * @retval timer cnt value(timer0~timer2 16bits cnt value, timer4 32bits cnt value)
  */
u32 ll_timer_cnt_get(TIMER_TypeDef *p_timer);

/**
  * @brief  set timer to count mode
  * @param  p_timer  : Structure pointer set to TIMERx
  * @param  cnt_cfg  : Structure pointer set to TIMERx counter mode
  * @retval None
  */
void ll_timer_cnt_mode_config(TIMER_TypeDef *p_timer, TYPE_LL_TIMER_CNT_CFG *cnt_cfg);

/**
  * @brief  set timer to pwm mode
  * @param  p_timer  : Structure pointer set to TIMERx
  * @param  pwm_cfg  : Structure pointer set to TIMERx pwm mode
  * @retval None
  */
void ll_timer_pwm_mode_config(TIMER_TypeDef *p_timer, TYPE_LL_TIMER_PWM_CFG *pwm_cfg);

/**
  * @brief  set timer to pwm mode
  * @param  p_timer  : Structure pointer set to TIMERx
  * @param  upper_limit  : Upper limit value
  * @param  lower_limit  : Lower limit value
  * @retval None Upper
  */
void ll_timer_dir_pin_limit_value(TIMER_TypeDef *p_timer, u32 upper_limit, u32 lower_limit);

/**
  * @brief  set timer to capture mode
  * @param  p_timer  : Structure pointer set to TIMERx
  * @param  cap_cfg  : Structure pointer set to TIMERx capture mode
  * @retval None
  */
void ll_timer_cap_mode_config(TIMER_TypeDef *p_timer, TYPE_LL_TIMER_CAP_CFG *cap_cfg);

/**
  * @brief  Low layer TIMERx to get the capture_1 count value
  * @param  p_timer   : Structure pointer set to TIMERx
  * @retval None
  */
u16 ll_timer_cap_cap1_get(TIMER_TypeDef *p_timer);

/**
  * @brief  Low layer TIMERx to get the capture_2 count value
  * @param  p_timer   : Structure pointer set to TIMERx
  * @retval None
  */
u16 ll_timer_cap_cap2_get(TIMER_TypeDef *p_timer);


/**
  * @brief  Low layer TIMERx synchronization signal selection 
  * @param  p_timer   : Structure pointer set to TIMERx
  * @param  synco_sel : TYPE_ENUM_LL_TIMER_SYNCO_SEL
  * @retval None
  */
void ll_timer_synco_sel_set(TIMER_TypeDef *p_timer, TYPE_ENUM_LL_TIMER_SYNCO_SEL synco_sel);

/**
  * @brief  Low layer TIMERx Synci MODE selection 
  * @param  p_timer    : Structure pointer set to TIMERx
  * @param  slave_mode : TYPE_ENUM_LL_TIMER_SLAVE_MODE
  * @retval None
  */
void ll_timer_slave_mode_set(TIMER_TypeDef *p_timer, TYPE_ENUM_LL_TIMER_SLAVE_MODE slave_mode);

/**
  * @brief  Low layer TIMER ALL Sync register set 
  * @param  p_timer    : Structure pointer set to TIMER_ALL
  * @param  data : TIMER0, TIMER1, TIMER2 clear cnt or kick start
  * @retval None
  */
void ll_timer_all_sync_mode_set(TIMER_ALL_TypeDef *p_timer, u32 data);


/**
* @}
  */
  
/** @defgroup TIMER_LL_Data_Transfers TIMER LL Data transfers functions
  * @brief    TIMER LL Data transfers functions 
  *
@verbatim   
  ===============================================================================
                            Data transfers functions
  ===============================================================================  

    This subsection provides a set of functions allowing to manage the TIMER data 
    transfers and receive.
  
@endverbatim
  *
  * @{
  */

/**
  * @brief  Low layer TIMERx Synci polarity reversed enabled function
  * @param  p_timer  : Structure pointer set to TIMERx
  * @retval None
  */
void ll_timer_synci_pol_enable(TIMER_TypeDef *p_timer);
/**
  * @brief  Low layer TIMERx Synci polarity reversed disable function
  * @param  p_timer  : Structure pointer set to TIMERx
  * @retval None
  */
void ll_timer_synci_pol_disable(TIMER_TypeDef *p_timer);
/**
  * @brief  Low layer TIMERx Synci polarity reversed get enable or disable function
  * @param  p_timer  : Structure pointer set to TIMERx
  * @retval result
  */
#define LL_TIMER_SYNCI_POL_GET(p_timer)                     ((p_timer)->TMR_CON & LL_TIMER_CON_SYNCI_POL)


/**
  * @brief  Low layer TIMERx enabled function
  * @param  p_timer  : Structure pointer set to TIMERx
  * @retval None
  */
void ll_timer_enable(TIMER_TypeDef *p_timer);
/**
  * @brief  Low layer TIMERx disable function
  * @param  p_timer  : Structure pointer set to TIMERx
  * @retval None
  */
void ll_timer_disable(TIMER_TypeDef *p_timer);
/**
  * @brief  Low layer TIMERx enabled get enable or disable function
  * @param  p_timer  : Structure pointer set to TIMERx
  * @retval result
  */
#define LL_TIMER_EN_GET(p_timer)                            ((p_timer)->TMR_EN & LL_TIMER_EN)

/**
  * @brief  Low layer Slave mode trigger mode or reset mode interrupt enable function
  * @param  p_timer  : Structure pointer set to TIMERx
  * @retval None
  */
void ll_timer_slave_mode_interrupt_enable(TIMER_TypeDef *p_timer);
/**
  * @brief  Low layer Slave mode trigger mode or reset mode interrupt disable function
  * @param  p_timer  : Structure pointer set to TIMERx
  * @retval None
  */
void ll_timer_slave_mode_interrupt_disable(TIMER_TypeDef *p_timer);
/**
  * @brief  Low layer Slave mode trigger mode or reset mode interrupt get enable or disable function
  * @param  p_timer  : Structure pointer set to TIMERx
  * @retval result
  */
#define LL_TIMER_SLAVE_MOED_INTERRUPT_GET(p_timer)          ((p_timer)->TMR_IE & LL_TIMER_IE_SLAVE_MOED_IE)

/**
  * @brief  Low layer CNT value = CMP value interrupt enable function
  * @param  p_timer  : Structure pointer set to TIMERx
  * @retval None
  */
void ll_timer_cnt_cmp_interrupt_enable(TIMER_TypeDef *p_timer);
/**
  * @brief  Low layer CNT value = CMP value interrupt disable function
  * @param  p_timer  : Structure pointer set to TIMERx
  * @retval None
  */
void ll_timer_cnt_cmp_interrupt_disable(TIMER_TypeDef *p_timer);
/**
  * @brief  Low layer CNT value = CMP value interrupt get enable or disable function
  * @param  p_timer  : Structure pointer set to TIMERx
  * @retval result
  */
#define LL_TIMER_CNT_CMP_INTERRUPT_GET(p_timer)             ((p_timer)->TMR_IE & LL_TIMER_IE_CNT_CMP_IE)

/**
  * @brief  Low layer CNT value = PRD value interrupt enable function
  * @param  p_timer  : Structure pointer set to TIMERx
  * @retval None
  */
void ll_timer_cnt_prd_interrupt_enable(TIMER_TypeDef *p_timer);
/**
  * @brief  Low layer CNT value = PRD value interrupt disable function
  * @param  p_timer  : Structure pointer set to TIMERx
  * @retval None
  */
void ll_timer_cnt_prd_interrupt_disable(TIMER_TypeDef *p_timer);
/**
  * @brief  Low layer CNT value = PRD value interrupt get enable or disable function
  * @param  p_timer  : Structure pointer set to TIMERx
  * @retval result
  */
#define LL_TIMER_CNT_PRD_INTERRUPT_GET(p_timer)             ((p_timer)->TMR_IE & LL_TIMER_IE_CNT_PRD_IE)

/**
  * @brief  Low layer CNT value overflows interrupt enable function
  * @param  p_timer  : Structure pointer set to TIMERx
  * @retval None
  */
void ll_timer_cnt_overflow_interrupt_enable(TIMER_TypeDef *p_timer);
/**
  * @brief  Low layer CNT value overflows interrupt disable function
  * @param  p_timer  : Structure pointer set to TIMERx
  * @retval None
  */
void ll_timer_cnt_overflow_interrupt_disable(TIMER_TypeDef *p_timer);
/**
  * @brief  Low layer CNT value overflows interrupt get enable or disable function
  * @param  p_timer  : Structure pointer set to TIMERx
  * @retval result
  */
#define LL_TIMER_CNT_OVERFLOW_INTERRUPT_GET(p_timer)        ((p_timer)->TMR_IE & LL_TIMER_IE_CNT_OVERFLOW_IE)

/**
  * @brief  Low layer capture event 2 occurs interrupt enable function
  * @param  p_timer  : Structure pointer set to TIMERx
  * @retval None
  */
void ll_timer_capture2_interrupt_enable(TIMER_TypeDef *p_timer);
/**
  * @brief  Low layer capture event 2 occurs interrupt disable function
  * @param  p_timer  : Structure pointer set to TIMERx
  * @retval None
  */
void ll_timer_capture2_interrupt_disable(TIMER_TypeDef *p_timer);
/**
  * @brief  Low layer capture event 2 occurs interrupt get enable or disable function
  * @param  p_timer  : Structure pointer set to TIMERx
  * @retval result
  */
#define LL_TIMER_CAPTURE2_INTERRUPT_GET(p_timer)            ((p_timer)->TMR_IE & LL_TIMER_IE_CAPTURE2_IE)

/**
  * @brief  Low layer capture event 1 occurs interrupt enable function
  * @param  p_timer  : Structure pointer set to TIMERx
  * @retval None
  */
void ll_timer_capture1_interrupt_enable(TIMER_TypeDef *p_timer);
/**
  * @brief  Low layer capture event 1 occurs interrupt disable function
  * @param  p_timer  : Structure pointer set to TIMERx
  * @retval None
  */
void ll_timer_capture1_interrupt_disable(TIMER_TypeDef *p_timer);
/**
  * @brief  Low layer capture event 1 occurs interrupt get enable or disable function
  * @param  p_timer  : Structure pointer set to TIMERx
  * @retval result
  */
#define LL_TIMER_CAPTURE1_INTERRUPT_GET(p_timer)            ((p_timer)->TMR_IE & LL_TIMER_IE_CAPTURE1_IE)
/**
  * @brief  TIMERx polarity reversed enabled function
  * @param  p_timer  : Structure pointer set to TIMERx
  * @retval None
  */
void ll_timer_pwm_pol_enable(TIMER_TypeDef *p_timer);

/**
  * @brief  TIMERx  polarity reversed disable function
  * @param  p_timer  : Structure pointer set to TIMERx
  * @retval None
  */
void ll_timer_pwm_pol_disable(TIMER_TypeDef *p_timer);
/**
  * @brief  TIMERx  gate kepp enable function
  * @param  p_timer  : Structure pointer set to TIMERx
  * @retval None
  */
void ll_timer_gate_keep_enable(TIMER_TypeDef *p_timer);
/**
  * @brief  TIMERx  gate kepp disable function
  * @param  p_timer  : Structure pointer set to TIMERx
  * @retval None
  */
void ll_timer_gate_keep_disable(TIMER_TypeDef *p_timer);
/**
  * @brief  timer pwm mode config
  * @param  p_timer : Structure pointer set to TIMERx
  * @param  freq_hz : PWM frequency
  * @param  duty_per : PWM duty cycle
  * @retval None  
  */
void ll_timer_pwm_config(TIMER_TypeDef *p_timer, u32 freq_hz, u8 duty_per);
/**
  * @brief  timer pwm mode config extend
  * @param  p_timer : Structure pointer set to TIMERx
  * @param  freq_hz : PWM frequency
  * @param  duty_per : PWM duty cycle
  * @retval None  
  */
void ll_timer_pwm_config_ex(TIMER_TypeDef *p_timer, u32 freq_hz, u8 duty_per, TYPE_ENUM_LL_TIMER_PWM_ACTIVE_LEVEL_SEL active_level);
/**
  * @brief  timer pwm duty fixed
  * @param  p_timer : Structure pointer set to TIMERx
  * @param  duty_per : PWM duty cycle
  * @retval None  
  */
void ll_timer_pwm_duty_fixed(TIMER_TypeDef *p_timer, u8 duty_per);
/**
  * @brief  timer pwm mode start
  * @param  p_timer  :   Structure pointer set to TIMERx
  * @retval None  
  */
void ll_timer_pwm_start(TIMER_TypeDef *p_timer);
/**
  * @brief  timer pwm mode stop
  * @param  p_timer  :   Structure pointer set to TIMERx
  * @note   
  * @retval None  
  */
void ll_timer_pwm_stop(TIMER_TypeDef *p_timer);
/**
  * @brief  timer count mode to set time
  * @param  p_timer : Structure pointer set to TIMERx, 
  * @param  value_us:timing time(us)
  * @note   
  * @retval None  
  */
void ll_timer_cnt_set_us(TIMER_TypeDef *p_timer, u32 value_us);
/**
  * @brief  timer count mode start
  * @param  p_timer  :   Structure pointer set to TIMERx
  * @note   
  * @retval None  
  */
void ll_timer_cnt_start(TIMER_TypeDef *p_timer);
/**
  * @brief  timer count mode stop
  * @param  p_timer  :   Structure pointer set to TIMERx
  * @note   
  * @retval None  
  */
void ll_timer_cnt_stop(TIMER_TypeDef *p_timer);

/**
  * @brief  TIMERx  polarity get enable or disable function
  * @param  p_timer  : Structure pointer set to TIMERx
  * @retval result
  */
#define LL_TIMER_PWM_POL_GET(p_timer)            ((p_timer)->TMR_CON & LL_TIMER_CON_PWM0_P_POL)
/**
  * @brief  Low layer timer get slave mode occurs pending function
  * @param  p_timer  : Structure pointer set to TIMERx
  * @retval result
  */
#define LL_TIMER_SLAVE_MOED_PENDING_GET(p_timer)            ((p_timer)->TMR_FLG & LL_TIMER_FLG_SLAVE_MOED_PENDING)

/**
  * @brief  Low layer timer clear slave mode occurs pending function
  * @param  p_timer  : Structure pointer set to TIMERx
  * @retval None
  */
#define LL_TIMER_SLAVE_MOED_PENDING_CLR(p_timer)            ((p_timer)->TMR_CLR = LL_TIMER_CLR_SLAVE_MOED_PENDING)

/**
  * @brief  Low layer timer get CNT value = CMP value pending function
  * @param  p_timer  : Structure pointer set to TIMERx
  * @retval result
  */
#define LL_TIMER_CNT_CMP_PENDING_GET(p_timer)               ((p_timer)->TMR_FLG & LL_TIMER_FLG_CNT_CMP_PENDING)

/**
  * @brief  Low layer timer clear CNT value = CMP value pending function
  * @param  p_timer  : Structure pointer set to TIMERx
  * @retval None
  */
#define LL_TIMER_CNT_CMP_PENDING_CLR(p_timer)               ((p_timer)->TMR_CLR = LL_TIMER_CLR_CNT_CMP_PENDING)

/**
  * @brief  Low layer timer get CNT value = PRD value pending function
  * @param  p_timer  : Structure pointer set to TIMERx
  * @retval result
  */
#define LL_TIMER_CNT_PRD_PENDING_GET(p_timer)               ((p_timer)->TMR_FLG & LL_TIMER_FLG_CNT_PRD_PENDING)

/**
  * @brief  Low layer timer clear CNT value = PRD value pending function
  * @param  p_timer  : Structure pointer set to TIMERx
  * @retval None
  */
#define LL_TIMER_CNT_PRD_PENDING_CLR(p_timer)               ((p_timer)->TMR_CLR = LL_TIMER_CLR_CNT_PRD_PENDING)

/**
  * @brief  Low layer timer get CNT value overflow pending function
  * @param  p_timer  : Structure pointer set to TIMERx
  * @retval result
  */
#define LL_TIMER_CNT_OVERFLOW_PENDING_GET(p_timer)          ((p_timer)->TMR_FLG & LL_TIMER_FLG_CNT_OVERFLOW_PENDING)

/**
  * @brief  Low layer timer clear CNT value overflow pending function
  * @param  p_timer  : Structure pointer set to TIMERx
  * @retval None
  */
#define LL_TIMER_CNT_OVERFLOW_PENDING_CLR(p_timer)          ((p_timer)->TMR_CLR = LL_TIMER_CLR_CNT_OVERFLOW_PENDING)

/**
  * @brief  Low layer timer get capture event 2 occurs pending function
  * @param  p_timer  : Structure pointer set to TIMERx
  * @retval result
  */
#define LL_TIMER_CAPTURE2_PENDING_GET(p_timer)              ((p_timer)->TMR_FLG & LL_TIMER_FLG_CAPTURE2_PENDING)

/**
  * @brief  Low layer timer clear capture event 2 occurs pending function
  * @param  p_timer  : Structure pointer set to TIMERx
  * @retval None
  */
#define LL_TIMER_CAPTURE2_PENDING_CLR(p_timer)              ((p_timer)->TMR_CLR = LL_TIMER_CLR_CAPTURE2_PENDING)

/**
  * @brief  Low layer timer get capture event 1 occurs pending function
  * @param  p_timer  : Structure pointer set to TIMERx
  * @retval result
  */
#define LL_TIMER_CAPTURE1_PENDING_GET(p_timer)              ((p_timer)->TMR_FLG & LL_TIMER_FLG_CAPTURE1_PENDING)

/**
  * @brief  Low layer timer clear capture event 1 occurs pending function
  * @param  p_timer  : Structure pointer set to TIMERx
  * @retval None
  */
#define LL_TIMER_CAPTURE1_PENDING_CLR(p_timer)              ((p_timer)->TMR_CLR = LL_TIMER_CLR_CAPTURE1_PENDING)

/**
  * @}
  */

/**
  * @}
  */

#ifdef __cplusplus
}
#endif

/**
  * @}
  */

/**
  * @}
  */

#endif //__JS32T031_LL_TIMER_H

/*************************** (C) COPYRIGHT 2022 JUSHENG ***** END OF FILE *****/
